/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.testis.gui.mvc.view;

import org.testis.gui.mvc.utilities.ImageFactory;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JRootPane;
import javax.swing.KeyStroke;

/**
 *
 * @author selcuk
 */
public class AtofBaseDialog extends JDialog {

    /** Creates new form AddTestPlanView */
    public AtofBaseDialog(Frame parent, boolean modal) {
        super(parent, modal);
    }

    // centers the dialog within the screen [1.1]
    public void centerScreen() {
        WindowLocationProvider wlp = new WindowLocationProvider(this);
        wlp.centerScreen();
    }

    // centers the dialog within the parent container [1.1]
    public void centerParent() {
        WindowLocationProvider wlp = new WindowLocationProvider(this);
        wlp.centerParent();
    }

    @Override
    protected JRootPane createRootPane() {
        ActionListener actionListener = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                dispose();
//                setVisible(false);
            }
        };
        JRootPane rp = super.createRootPane();
        KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
        rp.registerKeyboardAction(actionListener, stroke,
                JComponent.WHEN_IN_FOCUSED_WINDOW);
        return rp;
    }

    public void setDefaultButton(JButton defaultButton) {
        this.getRootPane().setDefaultButton(defaultButton);
    }

    public void setFrameIcon(String path) {
        ImageIcon iconImg = ImageFactory.instance().createImageIcon(path);
        if (iconImg != null) {
            setIconImage(iconImg.getImage());
        }
    }
}
